{% macro render_movie(movie, show_rating=true) %}
<div class="movie-item">
    <h4>{{ movie.name }} ({{ movie.year }})</h4>
    {% if show_rating %}
        <p>Rating: 
            {% if movie.rating >= 8 %}
                <span class="badge bg-success">{{ movie.rating }}/10</span>
            {% elif movie.rating >= 6 %}
                <span class="badge bg-warning text-dark">{{ movie.rating }}/10</span>
            {% else %}
                <span class="badge bg-danger">{{ movie.rating }}/10</span>
            {% endif %}
        </p>
    {% endif %}
    {% if movie.director %}
        <p>Director: {{ movie.director }}</p>
    {% endif %}
</div>
{% endmacro %}

{% macro render_form_field(field) %}
<div class="mb-3">
    {{ field.label(class="form-label") }}
    {{ field(class="form-control") }}
    {% if field.errors %}
        <div class="text-danger">
            {% for error in field.errors %}
                <small>{{ error }}</small>
            {% endfor %}
        </div>
    {% endif %}
</div>
{% endmacro %}

{% macro render_pagination(page, total_pages, endpoint) %}
<nav aria-label="Page navigation">
    <ul class="pagination">
        {% if page > 1 %}
            <li class="page-item">
                <a class="page-link" href="{{ url_for(endpoint, page=page-1) }}">Previous</a>
            </li>
        {% else %}
            <li class="page-item disabled">
                <span class="page-link">Previous</span>
            </li>
        {% endif %}
        
        {% for p in range([1, page-2]|max, [total_pages+1, page+3]|min) %}
            {% if p == page %}
                <li class="page-item active">
                    <span class="page-link">{{ p }}</span>
                </li>
            {% else %}
                <li class="page-item">
                    <a class="page-link" href="{{ url_for(endpoint, page=p) }}">{{ p }}</a>
                </li>
            {% endif %}
        {% endfor %}
        
        {% if page < total_pages %}
            <li class="page-item">
                <a class="page-link" href="{{ url_for(endpoint, page=page+1) }}">Next</a>
            </li>
        {% else %}
            <li class="page-item disabled">
                <span class="page-link">Next</span>
            </li>
        {% endif %}
    </ul>
</nav>
{% endmacro %}